package jok.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class MapDemo {

	public static void main(String[] args) {
		Map<String, Student> map = new HashMap<String, Student>();

		map.put("A001", new Student(1, "张三", 18));
		map.put("A002", new Student(2, "李四", 22));
		map.put("A003", new Student(3, "王五", 16));
		map.put("A004", null);
		map.put("A005", null);
		map.put(null, new Student(4, "赵六", 25));

		System.out.println(map);

		map.remove(null);
		System.out.println(map);

		Student s = map.get("A002");
		System.out.println(s);

		System.out.println("------------------");
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			System.out.println(map.get(key));
		}

		System.out.println("------------------");
		Set<Entry<String, Student>> entrys = map.entrySet();
		for (Entry<String, Student> entry : entrys) {
			System.out.println("key：" + entry.getKey() + "\tvalue："
					+ entry.getValue());
		}

		System.out.println("------------------");
		System.out.println(map.containsKey("A005"));
		System.out.println(map.containsValue(null));
		map.clear();
		System.out.println(map.isEmpty());

		Map<String, Student> map2 = new TreeMap<String, Student>();

		map2.put("A003", new Student(3, "王五", 16));
		map2.put("A001", new Student(1, "张三", 18));
		map2.put("A002", new Student(2, "李四", 22));

		System.out.println(map2);
		// {A001=Student [id=1, name=张三, age=18], A002=Student [id=2, name=李四,
		// age=22], A003=Student [id=3, name=王五, age=16]}
	}
}
